package com.abc.controller;

import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.*;

import java.util.UUID;

@RestController
@RequestMapping("/test")
public class Controller {

    @PostMapping("login")
    public JSONObject login(@RequestBody JSONObject jsonObject) {
        JSONObject jsonObjectResult = new JSONObject();
        if (jsonObject.getString("username").equals("罗睿") && jsonObject.getString("password").equals("123")) {
            jsonObjectResult.put("code", 0000);
            jsonObjectResult.put("msg", "登录成功");
            jsonObjectResult.put("data", "{}");
            return jsonObjectResult;
        }
        jsonObjectResult.put("code", -1);
        jsonObjectResult.put("msg", "登录失败");
        jsonObjectResult.put("data", "null");
        return jsonObjectResult;
    }

    @PostMapping("logout")
    public JSONObject logout(@RequestBody JSONObject jsonObject) {
        JSONObject jsonObjectResult = new JSONObject();
        if (jsonObject.getString("username").equals("罗睿") && jsonObject.getString("password").equals("123")) {
            jsonObjectResult.put("code", 0000);
            jsonObjectResult.put("msg", "退出成功");
            jsonObjectResult.put("data", "{}");
            return jsonObjectResult;
        }
        jsonObjectResult.put("code", -1);
        jsonObjectResult.put("msg", "退出失败");
        jsonObjectResult.put("data", "null");
        return jsonObjectResult;
    }

    @GetMapping("getuuid")
    public String getuuid() {
        String uuid = UUID.randomUUID().toString();
        return uuid;
    }

    @GetMapping("getUserId")
    public String getUserId(String username) {
        if ("罗睿".equals(username)) {
            return "1";
        }
        return null;
    }
}
